
window.addEventListener('load',function(){
	checkLogin();
	document.addEventListener('click',function(e){
		if(e.target.classList.contains('logout')){
			if(confirm('您确定退出当前账号么？')){
				localStorage.removeItem('nowUser');
				location.reload();
			}
		}
	})
	//按下s键搜索框自动获取光标
	document.onkeyup = function(e){
		if(e.keyCode==83){
			var searchBox = document.querySelector('.search .text')
			if(searchBox){
				searchBox.focus();
			}
		}
	}
})
//判断当前是否处于登录状态，并显示欢迎 或 提示 登录
function checkLogin(){
	var loginBox = document.querySelector('.welcome');
	var nowUser = localStorage.getItem('nowUser');
	console.log(nowUser);
	if(nowUser){
		loginBox.innerHTML="欢迎您,"+nowUser+' <a class="logout" href="javascript:;">登出</login>';
	}else{
		loginBox.innerHTML = '<a href="login.html">请登录!</a>&nbsp;&nbsp;<a href="register.html" class="style-red">免费注册</a>';
	}
}




